import VueRouter from 'vue-router'
import Vue from 'vue';
// import home from '../components/Home'
// import about from '../components/About'
// import user from '../components/User'

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
};

const originalreplace = VueRouter.prototype.replace;
VueRouter.prototype.replace = function replace(location) {
  return originalreplace.call(this, location).catch(err => err)
};

const routes = [
  {
    path:'',
    redirect:'home'
  },
  {
    path:'/home',
    meta:{
      title:'首页'
    },
    component:()=>import('../components/Home'),
    children:[
      {
        path:'',
        redirect:'homenews'
      },
      {
        path:'homenews',
        component:()=>import('../components/HomeNews')
      },
      {
        path:'homemessage',
        component:()=>import('../components/HomeMessage')
      }
    ]
  },
  {
    path:'/about',
    meta:{
      title:'关于'
    },
    component:()=>import('../components/About'),
    beforeEnter: (to, from, next) => {
      console.log('大溪地')
      next()
    }
  },
  {
    path:'/user/:userId',
    meta:{
      title:'用户'
    },
    component:()=>import('../components/User')
  }
  ,
  {
    path:'/profile',
    meta:{
      title:'个人信息'
    },
    component:()=>import('../components/Profile')
  }
]

const router = new VueRouter({
  routes,
  mode:'history',
  linkActiveClass:'activeWZ'
})

router.beforeEach((to,from,next)=>{
  next()
 
  document.title = to.matched[0].meta.title
})
export default router